const { DataTypes } = require('sequelize');
const sequelize = require('../../config/db');
const Order = require('./Order');
const Product = require('./Product');

const OrderItem = sequelize.define('order_item', {
  id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
  order_id: { type: DataTypes.INTEGER, references: { model: Order, key: 'id' } },
  product_id: { type: DataTypes.INTEGER, references: { model: Product, key: 'id' } },
  quantity: { type: DataTypes.INTEGER },
  price: { type: DataTypes.DECIMAL(10,2) }
}, {
  tableName: 'order_item',
  timestamps: false
});

OrderItem.belongsTo(Order, { foreignKey: 'order_id', as: 'order' });
OrderItem.belongsTo(Product, { foreignKey: 'product_id', as: 'product' });

module.exports = OrderItem;
